package com.huashi.dealer.commonEntity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.huashi.dealer.core.handler.HtmlContentTypeHandler;
import com.huashi.dealer.core.util.TimeUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 文章记录表
 * 对应数据库表：yoshop_message
 *
 * @author 系统生成
 * @since 2025-01-27
 */
@Data
@EqualsAndHashCode(callSuper = true)
@TableName(value = "yoshop_message", autoResultMap = true)
@Schema(description = "文章记录表")
public class Message extends BaseModel implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 文章id
     */
    @TableId(value = "message_id", type = IdType.AUTO)
    @Schema(description = "文章id")
    private Integer messageId;

    /**
     * 文章标题
     */
    @TableField("message_title")
    @Schema(description = "文章标题")
    private String messageTitle;

    /**
     * 列表显示方式(10小图展示 20大图展示)
     */
    @TableField("show_type")
    @Schema(description = "列表显示方式(10小图展示 20大图展示)")
    private Integer showType;

    /**
     * 文章分类id
     */
    @TableField("category_id")
    @Schema(description = "文章分类id")
    private Integer categoryId;

    @Schema(description = "图片地址")
    @TableField(exist = false)
    private String categoryName;

    /**
     * 封面图id
     */
    @TableField("image_id")
    @Schema(description = "封面图id")
    private Integer imageId;

    /**
     * 文章内容
     */
    @TableField(value = "message_content", typeHandler = HtmlContentTypeHandler.class)
    @Schema(description = "文章内容")
    private String messageContent;

    /**
     * 文章排序(数字越小越靠前)
     */
    @TableField("message_sort")
    @Schema(description = "文章排序(数字越小越靠前)")
    private Integer messageSort;

    /**
     * 文章状态(0隐藏 1显示)
     */
    @TableField("message_status")
    @Schema(description = "文章状态(0隐藏 1显示)")
    private Integer messageStatus;

    /**
     * 虚拟阅读量(仅用作展示)
     */
    @TableField("virtual_views")
    @Schema(description = "虚拟阅读量(仅用作展示)")
    private Integer virtualViews;

    /**
     * 实际阅读量
     */
    @TableField("actual_views")
    @Schema(description = "实际阅读量")
    private Integer actualViews;

    /**
     * 用户id
     */
    @TableField("user_id")
    @Schema(description = "用户id")
    private Integer userId;

    @TableField("pdf_id")
    @Schema(description = "pdf")
    private Integer pdfId;

    /**
     * 是否删除
     */
    @TableField("is_delete")
    @Schema(description = "是否删除")
    @TableLogic
    private Integer isDelete;

    /**
     * 创建时间
     */
    @TableField("create_time")
    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Long createTime;

    /**
     * 更新时间
     */
    @TableField("update_time")
    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Long updateTime;


    /**
     * 消息类型（10政策通知，20公司公告，30订单消息）
     */
    @TableField("is_type")
    @Schema(description = "消息类型（10政策通知，20公司公告，30订单消息）")
    private Integer isType;

    /**
     * 是否已读：0未读，1已读
     */
    @TableField("status")
    @Schema(description = "是否已读：0未读，1已读")
    private Integer status;

    @TableField("relate_id")
    @Schema(description = "关联id")
    private Integer relateId;

    @Schema(description = "图片地址")
    @TableField(exist = false)
    private String imageUrl;




    @Schema(description = "格式化创建日期")
    public String getCreateDateStr() {
        if (createTime == null) return "";
        return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new java.util.Date(createTime * 1000L));
    }

    @Schema(description = "格式化更新时间")
    public String getUpdateTimeStr() {
        if (createTime == null) return "";
        return new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
                .format(new java.util.Date(updateTime * 1000L));
    }
}